#define DEBUG
#include <cstdio>
#include <cstring>

#define INC(x, y) (x=(x+(y))%mods)

using namespace std;

typedef long long ll;
const int maxn=50000, maxk=500 ,mods=1000000007;

int n, k, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], s[maxn+1], cnt[maxn+1];
ll f[maxn+1][maxk+1], g[maxn+1][maxk+1];

int min(int a, int b) {
    return a<b ? a : b;
}

void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
}

ll solve(int o, int fa) {
    ll ret=0;
    cnt[o] = 1;
    for (int i=ind[o]; i; i=link[i]) {
        if (to[i]!=fa) {
            INC(ret, solve(to[i], o));
        }
    }

    static ll tf[2][maxk+1], tg[2][maxk+1];
    int p=0;
    memset(tf, 0, sizeof tf);
    tf[0][1] = 1;
    memset(tg, 0, sizeof tg);
    for (int i=ind[o]; i; i=link[i]) {
        if (to[i]!=fa) {
            p=!p;
            memset(tf[p], 0, sizeof tf[p]);
            memset(tg[p], 0, sizeof tg[p]);
            for (int x=0; x<=cnt[o]; x++) {
                for (int y=0; x+y<=k && y<k/2+k%2 && y<=cnt[to[i]]; y++) {
                    INC(tf[p][x+y], tf[!p][x]*f[to[i]][y]);
                }
                for (int y=0; x+y<=k && y<=cnt[to[i]]; y++) {
                    INC(tg[p][x+y], tf[!p][x]*g[to[i]][y]);
                    INC(tg[p][x+y], tg[!p][x]*f[to[i]][y]);
                }
            }
            cnt[o] = min(cnt[o]+cnt[to[i]], k);
        }
    }
    memcpy(f[o], tf[p], sizeof f[o]);
    memcpy(g[o], tg[p], sizeof g[o]);
    if (k%2==0) {
        INC(g[o][k/2], f[o][k/2]*(o<fa ? s[o] : s[fa])%mods);
    }
    for (int i=k/2+1; i<=cnt[o]; i++) {
        INC(g[o][i], f[o][i]*s[o]%mods);
    }
    f[o][0] = 1;
    return INC(ret, g[o][k]);
}

int main() {
    freopen("centroid.in", "r", stdin);
    freopen("centroid.out", "w", stdout);

    scanf("%d %d", &n, &k);
    for (int i=1; i<=n; i++) {
        scanf("%d", s+i);
    }
    for (int i=1; i<n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        addSide(x, y), addSide(y, x);
    }

    ll ans=0;
    if (k==1) {
        for (int i=1; i<=n; i++) {
            INC(ans, s[i]);
        }
    } else ans = solve(n, 0);
    printf("%lld\n", ans);

    return 0;
}
